﻿#include "MoveCell.h"
//using namespace AniTool;
//using namespace AniTool::Internal;
#include <QCoreApplication>

MoveCell::MoveCell(JistDocument *document,
                             QList<QGraphicsItem *> &cells,
                             const QPointF &oldPos)
    : m_document(document)
    , m_Cells(cells)
    , mOldPos(oldPos)
    , mNewPos(cells.at(0)->pos())
{
    setText(QCoreApplication::translate("Undo Commands", "Move Cell"));
    for(int k = 0; k < m_Cells.count(); k++){
        m_curPoint.append(m_Cells[k]->pos());
    }
}

void MoveCell::undo()
{
    for(int k = 0; k < m_Cells.count(); k++){
        ImageItem* item = (ImageItem*)m_Cells[k];
        item->setPos(item->x() - mOldPos.x(), item->y() - mOldPos.y());
    }
    //m_Cells.setPos(mOldPos);
}

void MoveCell::redo()
{
    for(int k = 0; k < m_Cells.count(); k++){
        ImageItem* item = (ImageItem*)m_Cells[k];
        item->setPos(m_curPoint[k]);
    }
    //m_Cells->setPos(mNewPos);
}
